package com.eachonline.smart.web.user;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eachonline.core.JsonResult;
import com.eachonline.core.Pagination;
import com.eachonline.smart.mapper.CertificatePictureMapper;
import com.eachonline.smart.mapper.SmartUserDetailMapper;
import com.eachonline.smart.model.CertificatePicture;
import com.eachonline.smart.model.CertificatePictureExample;
import com.eachonline.smart.model.SmartCourse;
import com.eachonline.smart.model.SmartUser;
import com.eachonline.smart.model.SmartUserDetail;
import com.eachonline.smart.model.SmartUserDetailExample;
import com.eachonline.smart.model.SmartUserExample;
import com.eachonline.smart.service.SmartUserService;
import com.eachonline.smart.web.common.CommonUtil;
import com.eachonline.smart.web.common.SmsUtil;
import com.eachonline.util.Md5Util;
import com.eachonline.util.RedisHelper;
import com.eachonline.util.StringUtil;
import com.eachonline.util.UUIDUtil;

@Controller
@RequestMapping("/user")
public class SmartUserController {
	
	private static final Logger logger =  Logger.getLogger(SmartUserController.class);
	
	@Autowired
	public SmartUserService userService;
	
	@Autowired
	public SmartUserDetailMapper userdetailMapper;
	
	@Autowired
	public CertificatePictureMapper certificatePictureMapper;

	 /**
     * 
     * @param session
     * @return  
     * @Description:发送验证码
     */
    @RequestMapping(value="/sendCode", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult sendCode(HttpSession session,String telephone,HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		if(StringUtil.isEmpty(telephone))
		{
			return new JsonResult(false,"手机号不能为空");
		}
		if(!CommonUtil.isMobileNO(telephone))
		{
			return new JsonResult(false,"手机号输入错误");
		}
		
		SmartUserExample example = new SmartUserExample();
		example.createCriteria().andLoginNameEqualTo(telephone);
		List<SmartUser> list = userService.selectByExample(example);
		if(list != null && !list.isEmpty())
		{
			return new JsonResult(false,"该手机号已注册");
		}
		
		/*HttpSession session = request.getSession();
		session.removeAttribute(telephone);*/
		//生成6位随机数
		 String code = CommonUtil.getCode();
		 String strCode = SmsUtil.sendMsgToUser(telephone, code);
		 RedisHelper.setex(telephone, code, 300);
		 System.out.println(strCode+"=strCode="+code);
		 return new JsonResult(true,code);
    }
    
    
    
	 /**
     * 
     * @param session
     * @return  
     * @Description:校验送验证码
     */
    @RequestMapping(value="/checkMsgCode", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult checkMsgCode(HttpSession session,String telephone,String verCode,HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		if(StringUtil.isEmpty(telephone))
		{
			return new JsonResult(false,"手机号不能为空");
		}
		if(!CommonUtil.isMobileNO(telephone))
		{
			return new JsonResult(false,"手机号输入错误");
		}
		

		boolean flag = userService.verificationCode(telephone,verCode);
		
		if(!flag)
		{
			return new JsonResult(false, "验证码为错误");
		}
	
		 return new JsonResult(true,"成功");
    }
     

    
	 /**
     * 
     * @param session
     * @return  
     * @Description:发送验证码
     */
    @RequestMapping(value="/sendCommonMsg", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult sendCommonMsgToUser(HttpSession session,String telephone,HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
 		response.setHeader("Access-Control-Allow-Methods", "POST");
 		if(StringUtil.isEmpty(telephone))
 		{
 			return new JsonResult(false,"手机号不能为空");
 		}
 		if(!CommonUtil.isMobileNO(telephone))
 		{
 			return new JsonResult(false,"手机号输入错误");
 		}
 		
 		//生成6位随机数
 		 String code = CommonUtil.getCode();
 		 String strCode = SmsUtil.sendCommonMsgToUser(telephone, code);
 		 RedisHelper.setex(telephone, code, 300);
 		 System.out.println(strCode+"=strCode="+code);
 		 return new JsonResult(true,code);
    }
    
    
    
    
	 /**
    * 
    * @param session
    * @return  
    * @Description:发送验证码
    */
   @RequestMapping(value="/sendMsgCode", method = { RequestMethod.POST })
   @ResponseBody
   public JsonResult sendMsgCode(HttpSession session,String telephone,HttpServletResponse  response){
   	
   	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		if(StringUtil.isEmpty(telephone))
		{
			return new JsonResult(false,"手机号不能为空");
		}
		if(!CommonUtil.isMobileNO(telephone))
		{
			return new JsonResult(false,"手机号输入错误");
		}
		
		/*HttpSession session = request.getSession();
		session.removeAttribute(telephone);*/
		
		SmartUserExample uex=new SmartUserExample();
		uex.createCriteria().andLoginNameEqualTo(telephone);
	  	List<SmartUser>  userList=  userService.selectByExample(uex);
	  	if(!userList.isEmpty()){
	  		return new JsonResult(false,"手机号已经注册过");
	  	}
		//生成6位随机数
		 String code = CommonUtil.getCode();
		 String strCode = SmsUtil.sendMsgToUser(telephone, code);
		 RedisHelper.setex(telephone, code, 300);
		 System.out.println(strCode+"=strCode="+code);
		 return new JsonResult(true,code);
   }
   
    
    
    
    /**
     * 
     * @param session
     * @return  
     * @Description:修改用户密码
     */
    @RequestMapping(value="/modifyUserPwdByMsg", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult modifyUserPwd(HttpSession session,String telephone,String newPwd, HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		if(StringUtil.isEmpty(telephone))
		{
			return new JsonResult(false,"手机号不能为空");
		}
		if(!CommonUtil.isMobileNO(telephone))
		{
			return new JsonResult(false,"手机号输入错误");
		}
		
		SmartUserExample example = new SmartUserExample();
		example.createCriteria().andLoginNameEqualTo(telephone);
		List<SmartUser> list = userService.selectByExample(example);
		if(list == null && list.isEmpty())
		{
			return new JsonResult(false,"该手机号未注册");
		}
		
		SmartUser  user =list.get(0);
		user.setPassword( Md5Util.encodeHex(Md5Util.encodeHex(newPwd)));
		userService.updateByPrimaryKey(user);
		return new JsonResult(true,"修改成功");
      
    }
    
    
    
    /**
     * 
     * @param session
     * @return  
     * @Description:用户列表
     */
    @RequestMapping(value="/manager/queryUserList", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult queryUserList(HttpServletRequest request,String telephone,String userRole,String status, HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		int start=1;
		if(StringUtil.isNotEmpty(request.getParameter("start")))
		{
		  start=Integer.valueOf(request.getParameter("start").toString());
		}
		
		int pageSize=8;
		if(StringUtil.isNotEmpty(request.getParameter("pageSize")))
		{
			pageSize=Integer.valueOf(request.getParameter("pageSize").toString());
		}
		
		int begin =pageSize*(start-1);
		
		SmartUserExample uexa=new SmartUserExample();
		com.eachonline.smart.model.base.BaseSmartUserExample.Criteria ucri=   uexa.createCriteria();
		
		if(StringUtil.isNotEmpty(telephone))
		{
			ucri.andLoginNameLike("%"+telephone+"%");
		}
		
		if(StringUtil.isNotEmpty(userRole))
		{
			ucri.andUserRoleEqualTo(userRole);
		}
		
		if(StringUtil.isNotEmpty(status))
		{
			ucri.andCheckStatusEqualTo(status);
		}
		
		Pagination<SmartUser>  userInfo=userService.queryByPage(uexa, begin, pageSize, " create_time desc");
	    Map<String,Object>  dataMap=new HashMap<String, Object>();
	    dataMap.put("userPageInfo", userInfo);
	    
		return new JsonResult(true, dataMap);
		
      
    }
    
    /**
     * 
     * @param session
     * @return  
     * @Description:用户列表
     */
    @RequestMapping(value="/manager/updateUserStatus", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult updateUserStatus(HttpServletRequest request,String userId,String comment,String status, HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		
		SmartUser user= userService.selectByPrimaryKey(userId);
		if(user==null)
		{
			return new JsonResult(false, "该用户不存在");
		}
		
		user.setCheckStatus(status);
		user.setComment(comment);
		if(status.equalsIgnoreCase("2"))
		{
			user.setUserRole("2");
			user.setUserSite("0");
		}
		
		userService.updateByPrimaryKeySelective(user);
		return new JsonResult(true, "成功");
		
      
    }
    
    
    /**
     * 
     * @param session
     * @return  
     * @Description:用户列表
     */
    @RequestMapping(value="/manager/userDetail", method = { RequestMethod.POST })
    @ResponseBody
    public JsonResult queryUserDetail(HttpServletRequest request,String userId, HttpServletResponse  response){
    	
    	response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		Map<String,Object> userInfo=new HashMap<String, Object>();
		SmartUser user= userService.selectByPrimaryKey(userId);
		if(user==null)
		{
			return new JsonResult(false, "该用户不存在");
		}
		
		userInfo.put("userName", user.getUserName());
		userInfo.put("loginName", user.getLoginName());
		userInfo.put("userHeadUrl", user.getUserHeadPicUrl());
		userInfo.put("userRole", user.getUserRole());
		userInfo.put("userInfo", user.getUserInfo());
		userInfo.put("userStatus", user.getCheckStatus());
		userInfo.put("userBirth", user.getUserBirth());
		userInfo.put("userQQ", user.getUserQq());
		userInfo.put("userWX", user.getUserWx());
		userInfo.put("userSex", user.getUserSex());
		userInfo.put("userAddress", user.getUserProvince()+""+user.getUserCity()+""+user.getUserAddress());
		userInfo.put("comment", user.getComment());

		
		SmartUserDetail userDetail=null;
		SmartUserDetailExample  udexa=new SmartUserDetailExample();
		udexa.createCriteria().andUserIdEqualTo(userId);
		List<SmartUserDetail> detailList=userdetailMapper.selectByExample(udexa);
		if(!detailList.isEmpty())
		{
			userDetail=detailList.get(0);
		}
		
		if(userDetail==null)
		{
			userInfo.put("userRealName", "");
			userInfo.put("userCardNo", "");
			userInfo.put("userFrontPic", "");
			userInfo.put("userVersoPic", "");
			userInfo.put("skillOrient", "");
			userInfo.put("workExp", "");
		}else{
			
			userInfo.put("userRealName", userDetail.getUserRealName());
			userInfo.put("userCardNo", userDetail.getUserCardNo());
			userInfo.put("userFrontPic", userDetail.getUserFrontCardpicUrl());
			userInfo.put("userVersoPic",userDetail.getUserVersoCardpicUrl());
			userInfo.put("skillOrient", userDetail.getSkillOrient());
			userInfo.put("workExp", userDetail.getWorkExp());
			
		}
		
		CertificatePictureExample  cerExa=new CertificatePictureExample();
		cerExa.createCriteria().andUserIdEqualTo(userId);
		
		List<CertificatePicture> certList= certificatePictureMapper.selectByExample(cerExa);
		if(certList.isEmpty())
		{
			userInfo.put("certList","");
		}else
		{
			userInfo.put("certList",certList);
		}
	    Map<String,Object> dataMap=new HashMap<String, Object>();
	    
	    dataMap.put("userInfo", userInfo);
		return new JsonResult(true, dataMap);
		
      
    }
    
    @RequestMapping(value = "/userRegister", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult userRegister(HttpServletResponse response,HttpServletRequest request,SmartUser user,String verCode)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		JsonResult result = new JsonResult();
		try {
			
			if(StringUtil.isEmpty(user.getLoginName()))
			{
				return new JsonResult(false, "手机号不能为空");
			}
			
			String telephone = user.getLoginName();
			
			boolean flag = userService.verificationCode(telephone,verCode);
			
			if(!flag)
			{
				return new JsonResult(false, "验证码为错误");
			}
			
			if(StringUtil.isEmpty(user.getUserName()))
			{
				return new JsonResult(false, "用户昵称不能为空");
			}
			
			if(StringUtil.isEmpty(user.getPassword()))
			{
				return new JsonResult(false, "用户密码不能为空");
			}
			
			if(StringUtil.isEmpty(user.getUserRole()))
			{
				user.setUserRole("1");//1是学员 2是教师
			}
			
			SmartUserExample example = new SmartUserExample();
			example.createCriteria().andLoginNameEqualTo(telephone);
			List<SmartUser> list = userService.selectByExample(example);
			if(list != null && !list.isEmpty())
			{
				return new JsonResult(false, "用户手机号已经被注册");
			}
			user.setSid(UUIDUtil.getUUID());
		    String password = Md5Util.encodeHex(Md5Util.encodeHex(user.getPassword()));
		    user.setPassword(password);
		    user.setCreateTime(new Date());
		    user.setUserName(user.getLoginName());
		    user.setCheckStatus("0");
			int row = userService.insert(user);
			if(row >0)
			{
				result.setCode("2000");
				result.setMessage("注册成功");
				return result;
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			result.setCode("5000");
			result.setMessage("系统异常请稍后再试");
		}
		
		return result;
	}
	
	@RequestMapping(value = "/updateUser", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult updateUser(HttpServletResponse response,HttpServletRequest request,SmartUser user)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		try {
			
			SmartUser currentUser=CommonUtil.getCurrentUser(request);
			userService.updateByPrimaryKeySelective(user);
			CommonUtil.updateCurrentUser(request, currentUser);
			user.setLastLoginTime(new Date());
			//request.getSession().setAttribute("currentUser", eduUser);
			Map<String,Object> dataMap=new HashMap<String, Object>();
			dataMap.put("js_sessionId", CommonUtil.getCurrentSession(request).getId());
			dataMap.put("eduUser", user);
			return new JsonResult(true,"修改成功",dataMap);
			
			 
		} catch (Exception e) {
			logger.error(e.getMessage());
			return new JsonResult(false,"修改失败");
		}
		
		
	}
	 
	@RequestMapping(value = "/userDetail", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult userDetail(HttpServletResponse response,HttpServletRequest request ,String userId)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		try {
			SmartUser user = userService.selectByPrimaryKey(userId);
			Map<String,Object> dataMap=new HashMap<String,Object>();
			dataMap.put("user", user);
			return new JsonResult(true,dataMap);
			 
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		
		return new JsonResult(false,"操作失败");
	}
	
	@RequestMapping(value = "/login", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult login(HttpServletResponse response,HttpServletRequest request,String loginName,String password)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		JsonResult result = new JsonResult();
		HttpSession session = request.getSession();
		String sessionId=session.getId();
		try {
			password = Md5Util.encodeHex(Md5Util.encodeHex(password));
			SmartUserExample example = new SmartUserExample();
			example.createCriteria().andLoginNameEqualTo(loginName).andPasswordEqualTo(password);
			List<SmartUser> userList = userService.selectByExample(example);
			if(null == userList || userList.isEmpty())
			{
				result.setCode("5000");
				result.setMessage("账号或密码错误");
				return result;
			}
			else
			{
				SmartUser eduUser = userList.get(0);
				eduUser.setLastLoginTime(new Date());
				session.setAttribute("currentUser", eduUser);
				//request.getSession().setAttribute("currentUser", eduUser);
				System.out.println("sessionId"+session.getId());
				Map<String,Object> resultMap=new HashMap<String, Object>();
				userService.updateByPrimaryKeySelective(eduUser);
				resultMap.put("js_sessionId", sessionId);
				resultMap.put("eduUser", eduUser);
				result.setData(resultMap);
				result.setCode("2000");
				result.setMessage("登录成功 ");
				return result;

			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			result.setCode("5000");
			result.setMessage("登录异常");
			
		}
		return result;
		 
	}

	
	@RequestMapping(value = "/logout", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult logout(HttpServletResponse response,HttpServletRequest request)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		HttpSession session=CommonUtil.getCurrentSession(request);
		if(session==null)
			return new JsonResult(true,"您已退出成功"); 
		
		session.invalidate();
		return new JsonResult(true,"退出成功");
	}
	
	
	/**
	 * 我的课程列表
	 * @param request
	 * @param response
	 * @return
	 */
	/*@RequestMapping(value = "/myCourse", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult myCourse(HttpServletRequest request,HttpServletResponse response)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		int start=1;
		if(StringUtil.isNotEmpty(request.getParameter("start")))
		{
		  start=Integer.valueOf(request.getParameter("start").toString());
		}
		
		int pageSize=8;
		if(StringUtil.isNotEmpty(request.getParameter("pageSize")))
		{
			pageSize=Integer.valueOf(request.getParameter("pageSize").toString());
		}
		int begin =pageSize*(start-1);
		
		SmartUser currentUser=CommonUtil.getCurrentUser(request);
		List<SmartCourse> courseList=userService.queryMyCourses(currentUser.getSid(),begin,pageSize);
		if(courseList==null||courseList.size()==0)
		{
			return new JsonResult(true,"没有购买课程"); 
		}
		List<SmartCourse> nostartList=new ArrayList<SmartCourse>(); 
		List<SmartCourse> startingList=new ArrayList<SmartCourse>(); 
		List<SmartCourse> endList=new ArrayList<SmartCourse>(); 
		for(SmartCourse course:courseList)
		{
			long nowTime=(new Date()).getTime();
			long startTime=course.getCourseStartTime().getTime();
			long endTime=course.getCourseEndTime().getTime();
			
			if(nowTime<startTime)
			{
				nostartList.add(course);
			}else if(nowTime>endTime)
			{
				endList.add(course);
			}else{
				
				startingList.add(course);
			}
			
		}
		Map<String,Object> dataMap=new HashMap<String, Object>();
		dataMap.put("nostartList", nostartList);
		dataMap.put("startingList", startingList);
		dataMap.put("endList", endList);
		return new JsonResult(true,dataMap); 
		
	}
	*/
	
	/**
	 * 我的未开始课程列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/myNoCourse", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult myNoCourse(HttpServletRequest request,HttpServletResponse response,String courseType,String categroyCode)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		int start=1;
		if(StringUtil.isNotEmpty(request.getParameter("start")))
		{
		  start=Integer.valueOf(request.getParameter("start").toString());
		}
		
		int pageSize=8;
		if(StringUtil.isNotEmpty(request.getParameter("pageSize")))
		{
			pageSize=Integer.valueOf(request.getParameter("pageSize").toString());
		}
		int begin =pageSize*(start-1);
		
		SmartUser currentUser=CommonUtil.getCurrentUser(request);
		List<SmartCourse> courseList=userService.queryMyNoStudyCourse(currentUser.getSid(), begin, pageSize,courseType,categroyCode);
		int sumRow=	userService.queryMyNoStudyCourseCount(currentUser.getSid(),courseType,categroyCode);
		Map<String,Object> dataMap=new HashMap<String, Object>();
		dataMap.put("noStartCourse", courseList);
		dataMap.put("sumRow", sumRow);
		
		return new JsonResult(true, "成功",dataMap);
	}
	
	
	/**
	 * 我的已结束课程列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/myDoneCourse", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult myDoneCourse(HttpServletRequest request,HttpServletResponse response,String courseType,String categroyCode)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		int start=1;
		if(StringUtil.isNotEmpty(request.getParameter("start")))
		{
		  start=Integer.valueOf(request.getParameter("start").toString());
		}
		
		int pageSize=8;
		if(StringUtil.isNotEmpty(request.getParameter("pageSize")))
		{
			pageSize=Integer.valueOf(request.getParameter("pageSize").toString());
		}
		int begin =pageSize*(start-1);
		
		SmartUser currentUser=CommonUtil.getCurrentUser(request);
		List<SmartCourse> courseList=userService.queryMyDoneStudyCourse(currentUser.getSid(), begin, pageSize,courseType,categroyCode);
		int sumRow=	userService.queryMyDoneStudyCourseCount(currentUser.getSid(),courseType,categroyCode);
		Map<String,Object> dataMap=new HashMap<String, Object>();
		dataMap.put("DoneStartCourse", courseList);
		dataMap.put("sumRow", sumRow);
		
		return new JsonResult(true, "成功",dataMap);
	}
	

	/**
	 * 我的进行中的课程列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/myCourseing", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult myCourseing(HttpServletRequest request,HttpServletResponse response,String courseType,String categroyCode)
	{
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		int start=1;
		if(StringUtil.isNotEmpty(request.getParameter("start")))
		{
		  start=Integer.valueOf(request.getParameter("start").toString());
		}
		
		int pageSize=8;
		if(StringUtil.isNotEmpty(request.getParameter("pageSize")))
		{
			pageSize=Integer.valueOf(request.getParameter("pageSize").toString());
		}
		int begin =pageSize*(start-1);
		
		SmartUser currentUser=CommonUtil.getCurrentUser(request);
		List<SmartCourse> courseList=userService.queryMyStudyingCourse(currentUser.getSid(), begin, pageSize,courseType,categroyCode);
		int sumRow=	userService.queryMyStudyingCourseCount(currentUser.getSid(),courseType,categroyCode);
		Map<String,Object> dataMap=new HashMap<String, Object>();
		dataMap.put("IngStartCourse", courseList);
		dataMap.put("sumRow", sumRow);
		
		return new JsonResult(true, "成功",dataMap);
	}
	
	
	@RequestMapping(value = "/updatePwd", method = { RequestMethod.POST })
	@ResponseBody
	public JsonResult updatePwd(HttpServletResponse response, String userId,
			String oldPwd, String newPwd) {
		
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "POST");
		if (StringUtil.isEmpty(oldPwd) || StringUtil.isEmpty(newPwd)) {
			return new JsonResult(false, "原密码或新密码为空");
		}
		SmartUser eduUser = userService.selectByPrimaryKey(userId);
		
		String oldPwds = Md5Util.encodeHex(Md5Util.encodeHex(oldPwd));
		if(!oldPwds.equals(eduUser.getPassword()))
		{
			return new JsonResult(false, "原密码输入错误");
		}
		if (oldPwd.equals(newPwd)) {
			return new JsonResult(false, "新密码和原密码输入一致");
		}
		
		String password = Md5Util.encodeHex(Md5Util.encodeHex(newPwd));
		SmartUser user = new SmartUser();
		user.setSid(userId);
		user.setPassword(password);
		int row = userService.updateByPrimaryKeySelective(user);
		if (row > 0) {
			return new JsonResult(true, "操作成功");
		}
		return new JsonResult(false, "操作失败");
	}
	

}
